﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ManageBanking.Models;
namespace ManageBanking.Controllers
{
    public class RequestController : Controller
    {
        //
        // GET: /Request/
        CashierModels cs = new CashierModels();
        ManageUserModels mu = new ManageUserModels();
        LoginModels lg = new LoginModels();
        RequestAdminModels ram = new RequestAdminModels();
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult RequestAdmin()
        {

            ViewData["CheckII"] = Session["CheckII"];
            ViewData["user1"] = Session["user1"];
            ViewData["email"] = Session["email"];
            Session.Remove("CheckII");
            Session.Remove("user1");
            Session.Remove("email");

            return View();
        }
        public ActionResult ResolveRequest(string username, string sec_password, string idcard, string Email,int idType)
        {
                
                if (mu.CheckUSer(username) == true)
                {
                    Session["User"] = lg.Login_Acc(username);

                    
                }

                Username ac = (Username)Session["User"];

                if (mu.CheckUSer(username) == false)
                {
                    Session["CheckII"] = "Username not exist,Try Again ";
                    Session["user1"] = username;
                    Session["email"] = Email;
                    return RedirectToAction("RequestAdmin");

                }



                else  if (cs.CheckLock(ac.IdUsername) == 0)
                    {
                       
                    Session["CheckII"] = "You Don't Have Any Accunt Activate,So Can't Use This Support ";
                    Session["user1"] = username;
                    Session["email"] = Email;
                    return RedirectToAction("RequestAdmin");

                    
                    }




                    else if (mu.AnswerSecondary(ac.Username1, ram.getMD5(sec_password)) == false)
                    {
                        Session["CheckII"] = "Wrong Secondary Password, Try Again";
                        Session["user1"] = username;
                        Session["email"] = Email;
                        return RedirectToAction("RequestAdmin");

                    }




                    else if (mu.AnswerIdentity1(ac.Username1, idcard) == false)
                    {

                        Session["CheckII"] = "Wrong Identify Card,Try Again";
                        Session["user1"] = username;
                        Session["email"] = Email;


                        return RedirectToAction("RequestAdmin");

                    }





                    else if (mu.AnswerEmail(ac.Username1, Email) == true)
                    {
                        if (idType == 2)
                        {
                            if (mu.CheckLock(username) == false)
                            {
                                Session["CheckII"] = "This Username is not locked";
                                return RedirectToAction("RequestAdmin");
                            }
                            else
                            {
                                Session.Remove("user1");
                                Session.Remove("email");
                                Session.Remove("CheckII");
                                Session["CheckII"] = "true";
                                //1: ForgotPass
                                //2: Unlock


                                ram.AddRequest(ac.IdUsername, idType);
                                return RedirectToAction("RequestAdmin");
                            }

                        }
                        else
                        {
                            Session.Remove("user1");
                            Session.Remove("email");
                            Session.Remove("CheckII");
                            Session["CheckII"] = "true";
                            //1: ForgotPass
                            //2: Unlock


                            ram.AddRequest(ac.IdUsername, idType);
                            return RedirectToAction("RequestAdmin");
                        }

                    }
                    else
                    {

                        Session["CheckII"] = "Wrong Email,Try Again";
                        Session["user1"] = username;
                        Session["email"] = Email;


                        return RedirectToAction("RequestAdmin");

                    }


            
           
        }
    }
}
